package flc.ast.activity;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;

import android.app.Activity;
import android.content.Intent;
import android.view.View;

import com.hjq.bar.TitleBar;
import com.stark.calculator.tax.SpecDescActivity;
import com.stark.calculator.tax.constant.TaxConst;
import com.stark.calculator.tax.model.DataProvider;

import flc.ast.BaseAc;
import flc.ast.R;
import flc.ast.databinding.ActivityMyDeductionBinding;
import flc.ast.fragment.MyDeductionFragment;
import stark.common.basic.event.EventStatProxy;

public class MyDeductionActivity extends BaseAc<ActivityMyDeductionBinding> {

    private MyDeductionFragment mDeductionFragment;

    @Override
    protected int onCreate() {
        return R.layout.activity_my_deduction;
    }

    @Override
    protected void initView() {
        EventStatProxy.getInstance().statEvent1(this, mDataBinding.event1Container);
        mDataBinding.ivDeductionBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        });
        mDataBinding.ivDesc.setOnClickListener(this);
        mDeductionFragment=new MyDeductionFragment();
        getSupportFragmentManager().beginTransaction().replace(R.id.frContainer,mDeductionFragment).commit();
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void onClickCallback(View v) {
        switch (v.getId()){
            case R.id.ivDesc:
                startActivity(MySpecDescActivity.class);
                break;
        }
    }

    @Override
    public void onBackPressed() {
        //退出该界面时，要保存下附加扣除数据
        DataProvider.saveDeductions(mDeductionFragment.getDeductionBeanList());
        Intent intent = new Intent();
        intent.putParcelableArrayListExtra(TaxConst.KEY_DEDUCTIONS, mDeductionFragment.getDeductionBeanList());
        setResult(RESULT_OK, intent);
        finish();
    }

}